package com.changgou.search.service.impl;

import com.changgou.search.service.SearchService;
import org.apache.commons.lang.StringUtils;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.Operator;
import org.elasticsearch.index.query.QueryBuilders;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
import org.springframework.stereotype.Service;

import java.util.Map;
@Service
public class SearchServiceImpl implements SearchService{
    @Autowired
   private ElasticsearchTemplate elasticsearchTemplate;

    //设置每页查询条数据
    public final static Integer PAGE_SIZE = 20;

    @Override
    public Map search(Map<String, String> searchMap) {
        //查询条件
        if (searchMap!=null){
            BoolQueryBuilder boolQuery = QueryBuilders.boolQuery();
            if (!StringUtils.isEmpty(searchMap.get("keyword"))){
                // 关键词
                boolQuery.must(QueryBuilders.matchQuery("name",searchMap.get("keyword")).operator(Operator.AND));
            }


        }
        //封装查询结果
        return null;
    }
}
